import cv2
import numpy as np

# 二值化的处理一定基于灰度化（单通道图）
# 灰度化
gray = cv2.imread("./img/color.png", 0)

h, w = gray.shape
for i in range(h):
    for j in range(w):
        if gray[i, j] > 127: # 127 ==> 阈值
            gray[i, j] = 255 # 白色
        else:
            gray[i, j] = 0 # 黑色

cv2.imshow("img", gray)
cv2.waitKey(0)
